package com.atguigu.practice;

import java.util.ArrayList;
import java.util.List;

public class combine {
    public static List<List<Integer>> combineBetween(int n,int k){
        List<List<Integer>> res=new ArrayList<>();
        process(1,k,new ArrayList<>(),res,n);
        return res;
    }
    public static void process(int i,int k,List<Integer> list,List<List<Integer>> res,int n){
        if(list.size()==k || i>n){
            if(list.size()==k){
                res.add(list);
            }
            return;
        }else{
            List<Integer> resKeep=copyList(list);
            resKeep.add(i);
            process(i+1,k,resKeep,res,n);
            List<Integer> resNoInclude=copyList(list);
            process(i+1,k,resNoInclude,res,n);
        }
    }
    public static List<Integer> copyList(List<Integer> list){
        List<Integer> res=new ArrayList<>();
        for(int i=0;i<list.size();i++){
            res.add(list.get(i));
        }
        return res;
    }
}
